package com.yyfax.pay.order.model.to.auth;

import javax.validation.constraints.Pattern;

import org.apache.commons.lang3.StringUtils;
import org.hibernate.validator.constraints.NotBlank;

import com.yyfax.commons.lang.IdCardValidateUtil;
import com.yyfax.framework.exception.YYException;
import com.yyfax.framework.model.Params;
import com.yyfax.framework.yyfax.enums.RspCodeEnum;

/**
 * 无验证码独立鉴权请求参数
 * 
 * @author xulqb
 * @date 2017/12/21 10:32
 * @since v1.0.0
 */
@SuppressWarnings("serial")
public class AuthWithoutVerifyDirectParams extends Params {

	/**
	 * 用户端请求IP
	 */
	@NotBlank(message = "userIp不能为空")
	private String userIp;

	/**
	 * 商户订单号
	 */
	@NotBlank(message = "orderId不能为空")
	private String orderId;

	/**
	 * 订单时间
	 */
	@NotBlank(message = "orderTime不能为空")
	@Pattern(regexp = "([0-9]{4}[-][0-9]{2}[-][0-9]{1,2}[ ][0-9]{2}[:][0-9]{2}[:][0-9]{2})", message = "orderTime格式有误")
	private String orderTime;

	/**
	 * 过期时间
	 */
	@NotBlank(message = "expireTime不能为空")
	@Pattern(regexp = "([0-9]{4}[-][0-9]{2}[-][0-9]{1,2}[ ][0-9]{2}[:][0-9]{2}[:][0-9]{2})", message = "expireTime时间格式有误")
	private String expireTime;

	/**
	 * 商户用户ID
	 */
	@NotBlank(message = "userId不能为空")
	private String userId;

	/**
	 * 证件姓名
	 */
	@NotBlank(message = "name不能为空")
	private String name;

	/**
	 * 身份证号
	 */
	@NotBlank(message = "idNo不能为空")
	private String idNo;

	/**
	 * 银行卡号
	 */
	@NotBlank(message = "cardNo不能为空")
	private String cardNo;

	/**
	 * 手机号
	 */
	@NotBlank(message = "phone不能为空")
	private String phone;

	/**
	 * 偏好支付通道编号
	 */
	@NotBlank(message = "paymentCode不能为空")
	private String paymentCode;

	@Override
	public boolean validate() throws Exception {
		// 验证身份证合法性
		if (StringUtils.isNotBlank(this.idNo)) {
			if (!IdCardValidateUtil.isIdCard(idNo)) {
				throw new YYException(RspCodeEnum.COMMON_ERROR_PARAMETER_INVALID, "idNo格式不正确", "idNo格式不正确");
			}
		}

		return true;
	}

	public String getUserIp() {
		return userIp;
	}

	public void setUserIp(String userIp) {
		this.userIp = userIp;
	}

	public String getOrderId() {
		return orderId;
	}

	public void setOrderId(String orderId) {
		this.orderId = orderId;
	}

	public String getOrderTime() {
		return orderTime;
	}

	public void setOrderTime(String orderTime) {
		this.orderTime = orderTime;
	}

	public String getExpireTime() {
		return expireTime;
	}

	public void setExpireTime(String expireTime) {
		this.expireTime = expireTime;
	}

	public String getUserId() {
		return userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getIdNo() {
		return idNo;
	}

	public void setIdNo(String idNo) {
		this.idNo = idNo;
	}

	public String getCardNo() {
		return cardNo;
	}

	public void setCardNo(String cardNo) {
		this.cardNo = cardNo;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public String getPaymentCode() {
		return paymentCode;
	}

	public void setPaymentCode(String paymentCode) {
		this.paymentCode = paymentCode;
	}
}